import { VueComponent, Prop } from 'vue-typescript'
import { dataService } from '../../service/dataService'
import * as VueRouter from 'vue-router'

Vue.use(VueRouter);
var router = new VueRouter();

@VueComponent({
    template: require('./userInfo.html')
})

export class UserInfoComponent extends Vue{
    el:'#save'
    components:({
        userInfo:any,
    })
    ready(){
       this.userName = window.sessionStorage.getItem("userName");
       this.userGroupName="客户单位";
       this.userPassword='';
       this.rUserPassword='';
       this.rUserPasswordAgain='';
    }
    @Prop  
    //v-model初始化
    userName:string='';
    userGroupName:string='';
    userPassword:string='';
    rUserPassword:string='';
    rUserPasswordAgain:string='';
    save = function(){
        dataService().User.updatePassword(this.userPassword,this.rUserPassword,this.rUserPasswordAgain).then((res)=>{
            var oldPassword = window.sessionStorage.getItem("password");
            if(res&&res.success!==true&&this.userPassword != oldPassword){
                bootbox.alert("原密码不正确！");
            }else{
                bootbox.confirm("密码修改成功，请重新登陆！",()=>{
                    router.go('/login');
                });
            }
        });
    }
}